<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>Test Page for geoPolygonUtils.geometry.Precision class</title>
  <script language="JavaScript" type="text/javascript"
      src="../tools/jsunit/app/jsUnitCore.js"></script>
  <script language="JavaScript" type="text/javascript"
      src="../src/geometry.js"></script>
  <script language="JavaScript" type="text/javascript">

    // Alias for the Precision class.
    var Precision = geoPolygonUtils.geometry.Precision;

    
    function testPrecisionConstructor() {
      var precision = new Precision(1, 2, 3);
      assertEquals(1, precision.EPSILON);
      assertEquals(2, precision.UNIT);
      assertEquals(3, precision.RADIAN);
    };
    
    
    function testCreateForEpsilon() {
      var precision = Precision.createForEpsilon();
      assertTrue(Math.abs(precision.EPSILON) < 1e-6);
      assertTrue(Math.abs(precision.UNIT) < 1e-6);
      assertTrue(Math.abs(precision.RADIAN) < 1e-6);
      
      var undefinedVar;
      precision = Precision.createForEpsilon(undefinedVar);
      assertTrue(Math.abs(precision.EPSILON) < 1e-6);
      assertTrue(Math.abs(precision.UNIT) < 1e-6);
      assertTrue(Math.abs(precision.RADIAN) < 1e-6);
      
      precision = Precision.createForEpsilon(1);
      assertEquals(1, precision.EPSILON);
      assertTrue(Math.abs(precision.UNIT) < 1e-6);
      assertTrue(Math.abs(precision.RADIAN) < 1e-6);
      
      precision = Precision.createForEpsilon(new Precision(1, 2, 3));
      assertEquals(1, precision.EPSILON);
      assertEquals(2, precision.UNIT);
      assertEquals(3, precision.RADIAN);
    };
    
    
    function testCreateForUnit() {
      var precision = Precision.createForUnit();
      assertTrue(Math.abs(precision.EPSILON) < 1e-6);
      assertTrue(Math.abs(precision.UNIT) < 1e-6);
      assertTrue(Math.abs(precision.RADIAN) < 1e-6);
      
      var undefinedVar;
      precision = Precision.createForUnit(undefinedVar);
      assertTrue(Math.abs(precision.EPSILON) < 1e-6);
      assertTrue(Math.abs(precision.UNIT) < 1e-6);
      assertTrue(Math.abs(precision.RADIAN) < 1e-6);
      
      precision = Precision.createForUnit(1);
      assertTrue(Math.abs(precision.EPSILON) < 1e-6);
      assertEquals(1, precision.UNIT);
      assertTrue(Math.abs(precision.RADIAN) < 1e-6);
      
      precision = Precision.createForUnit(new Precision(1, 2, 3));
      assertEquals(1, precision.EPSILON);
      assertEquals(2, precision.UNIT);
      assertEquals(3, precision.RADIAN);
    };
    
    
    function testCreateForRadian() {
      var precision = Precision.createForRadian();
      assertTrue(Math.abs(precision.EPSILON) < 1e-6);
      assertTrue(Math.abs(precision.UNIT) < 1e-6);
      assertTrue(Math.abs(precision.RADIAN) < 1e-6);
      
      var undefinedVar;
      precision = Precision.createForRadian(undefinedVar);
      assertTrue(Math.abs(precision.EPSILON) < 1e-6);
      assertTrue(Math.abs(precision.UNIT) < 1e-6);
      assertTrue(Math.abs(precision.RADIAN) < 1e-6);
      
      precision = Precision.createForRadian(1);
      assertTrue(Math.abs(precision.EPSILON) < 1e-6);
      assertTrue(Math.abs(precision.UNIT) < 1e-6);
      assertEquals(1, precision.RADIAN);
      
      precision = Precision.createForRadian(new Precision(1, 2, 3));
      assertEquals(1, precision.EPSILON);
      assertEquals(2, precision.UNIT);
      assertEquals(3, precision.RADIAN);
    };
    
    
    function testIsZero() {
      assertTrue(Precision.isZero(0, 1e-16));
      assertTrue(Precision.isZero(1e-14, 1e-8));
      assertFalse(Precision.isZero(1e-8, 1e-14));
    };
    
    
    function testEqual() {
      assertTrue(Precision.equal(-1, -1, 1e-16));
      assertTrue(Precision.equal(-666, -665.99991, 1e-3));
      assertFalse(Precision.equal(-666, -665.99991, 1e-7));
    };
    
    
    function testCmp() {
      assertTrue(Precision.cmp(-1, 5, 1e-16) < 0);
      assertTrue(Precision.cmp(3, 3, 1e-8) == 0);
      assertTrue(Precision.cmp(2.99991, 3.0001, 1e-3) == 0);
      assertTrue(Precision.cmp(6, 3, 1e-3) > 0);
    };

  </script>
  <style>
    .code {
      color: green;
      font-weight: bold;
    }
  </style>
</head>
<body>
  <h1>Test Page for <span class="code">geoPolygonUtils.geometry.Precision</span>
  class.</h1>
  <p>This page contains tests for the methods of <span class="code">
  geoPolygonUtils.geometry.Precision</span> class. To see them take a look at
  the source of the page.</p>
  <p><em>Note:</em> this file is intended to be used with
  <a href="http://www.jsunit.net/">JSUnit</a> test framework.</p>
</body>
</html>
